
let nav1 = document.getElementById("nav1")
let li = document.getElementsByTagName("li")
let search = document.getElementById("search")
// 头部代码
window.onscroll = function () {
   if (window.scrollY == 0) {
      nav1.style.backgroundColor = "transparent"
      for (var i = 0; i < 14; i++) {
         li[i].style.color = "white"
         nav1.style.borderBottom = "1px transparent solid"
      }
   } else if (window.scrollY != 0) {
      nav1.style.backgroundColor = "white"
      nav1.style.borderBottom = "1px rgb(185, 182, 182) solid"
      for (var i = 0; i < 14; i++) {
         li[i].style.color = "black"
      }
   }

}
// 获取屏幕高度
// console.log( nav1.getBoundingClientRect().top)
// 轮播图代码
let carousel = document.getElementById("carousel-img")
let img = ["image/凑数.webp", "image/凑数2.webp", "image/凑数3.webp", "image/凑数4.webp", "image/凑数5.webp", "image/凑数6.webp"]
let timer = 0
function carouselChange() {
   if (timer <= 5) {
      carousel.src = img[timer]
      timer++
   } else {
      timer = 0
      carousel.src = img[timer]
   }

}
let carouselStart = setInterval(carouselChange, 2000)

// 轮播图左右按钮
let left = document.getElementById("left")
let right = document.getElementById("right")
left.onclick = function () {
   if (timer <= 0) {
      timer = 5
      carousel.src = img[5]
   } else {
      carousel.src = img[timer -= 1]
   }
}
right.onclick = function () {
   if (timer >= 6) {
      carousel.src = img[0]
      timer++
   } else {
      carousel.src = img[timer++]
   }
}
// 轮播图底部按钮
var btn = document.getElementsByClassName("btn")
// btn[0].onclick = function () {
//    carousel.src = img[0]
// }
function carouselChange2() {
   for (var i = 0; i < btn.length; i++) {
      let change = i
      function carouselChange3(i) {
         carousel.src = img[i]
      }
      btn[i].onclick = function () {

         carouselChange3(change)
      }
   }
}
carouselChange2()



